package spring.cloud.helloworld.zuul.service;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;

@Component
public class DemoFilter extends ZuulFilter{
	private static Logger log = LoggerFactory.getLogger(DemoFilter.class);
	@Override
	public Object run() {
		RequestContext rc = RequestContext.getCurrentContext();
		HttpServletRequest request = rc.getRequest();
		String s = String.format("%s >>> %s",request.getMethod(),request.getRequestURL().toString());
		log.info(request.getRequestURL().toString());
		log.info(s);
		return null;
	}

	@Override
	public boolean shouldFilter() {
		return true; //永远过滤
	}

	@Override
	public int filterOrder() {
		return 0;//优先级，数字越大，优先级越低
	}

	@Override
	public String filterType() {
		return "pre"; //pre：路由之前 , routing：路由之时  ,post： 路由之后,error：发送错误调用
	}

}
